﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Data.SQLite;

namespace DatabaseUtils {
  public class DataUtils {

    public static void SetValueFromDataReader( object property, object dataReaderValue ) {
      TypeConverter typeConverter = TypeDescriptor.GetConverter( dataReaderValue, true );
      if ( dataReaderValue != null && dataReaderValue != DBNull.Value ) {
        property = typeConverter.ConvertTo( dataReaderValue, property.GetType( ) );
      }
    }

    public static void SetValue( object property, string columnName, SQLiteDataReader dataReader ) {
      object value = dataReader.GetValue( dataReader.GetOrdinal( columnName ) );
      TypeConverter typeConverter = TypeDescriptor.GetConverter( value );
      if ( value!=null ) {
        property = typeConverter.ConvertTo( value, property.GetType( ) );
      }

    }

  }
}
